package pATT.DataSetsGenerator.dataSetsGenerator.core.visual;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.JWindow;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;

import pATT.DataSetsGenerator.dataSetsGenerator.converter.implement.Converter;
import pATT.DataSetsGenerator.dataSetsGenerator.converter.implement.XMLBayesConverter;
import pATT.DataSetsGenerator.dataSetsGenerator.core.implement.Relation;
import pATT.DataSetsGenerator.dataSetsGenerator.core.implement.RelationManager;
import pATT.DataSetsGenerator.dataSetsGenerator.core.visual.RelationGenerator.ToDoListModel;
import pATT.DataSetsGenerator.dataSetsGenerator.generator.visual.AssociationFrame;
import pATT.DataSetsGenerator.dataSetsGenerator.generator.visual.RandomExponentialFrame;
import pATT.DataSetsGenerator.dataSetsGenerator.generator.visual.RandomFrame;
import pATT.DataSetsGenerator.dataSetsGenerator.generator.visual.RandomGaussianFrame;
import pATT.DataSetsGenerator.dataSetsGenerator.generator.visual.RandomPoissonFrame;
import pATT.DataSetsGenerator.dataSetsGenerator.generator.visual.RandomWithWeightFrame;
import pATT.DataSetsGenerator.dataSetsGenerator.transaction.implement.LogTransaction;
import pATT.DataSetsGenerator.dataSetsGenerator.transaction.implement.Transaction;
import pATT.core.visual.UserProfilingUI;
import pATT.help.visual.HelpFrame;
import pATT.logger.Message;



@SuppressWarnings("serial")
public class DataGenerator extends JFrame{
	
	private JPanel jContentPane = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel jPanel = null;
	private JScrollPane jScrollPane = null;
	private JComboBox jComboBox = null;
	private JLabel jLabel = null;
	private JScrollPane jScrollPane1 = null;
	private JTable jTable = null;
	private JTextArea jTextArea = null;
	private int contTable=0;
	private LogTransaction logger = null;	
	public static DataGenerator instance = null;  //  @jve:decl-index=0:visual-constraint="760,13"
	private JButton jCreateRelationsButton = null;
	private JButton jGeneratorButton = null;
	private JButton jSaveFileButton = null;
	private JWindow jGeneratorWindow = null;
	private JScrollPane jGeneratorScrollPane = null;
	private JTree jGeneratorTree = null;
	private JButton jHelpButton = null;
	private JButton jParserButton = null;
	private JTree jTree = null;
	private JWindow jWindow = null;
	private JScrollPane jChooseScrollPane1 = null;
	private Hashtable<String,Converter> hash = new Hashtable<String,Converter>();
	private JLabel jTransactionLabel = null;
	public static DataGenerator createInstance(){
		instance = new DataGenerator();
		return instance;
	}
	
	public DataGenerator() throws HeadlessException {
		super();
		// TODO Auto-generated constructor stub
		initialize();
	}
	
	public DataGenerator(GraphicsConfiguration arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
		initialize();
	}
	
	public DataGenerator(String arg0) throws HeadlessException {
		super(arg0);
		// TODO Auto-generated constructor stub
		initialize();
	}
	
	public DataGenerator(String arg0, GraphicsConfiguration arg1) {
		super(arg0, arg1);
		// TODO Auto-generated constructor stub
		initialize();
	}
	
	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.setBounds(new java.awt.Rectangle(223,82,554,472));
			jTabbedPane.setForeground(java.awt.Color.blue);
			jTabbedPane.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jTabbedPane.setBackground(java.awt.SystemColor.control);
			jTabbedPane.setPreferredSize(new java.awt.Dimension(555,339));
			jTabbedPane.addTab("Generator Output", null, getJPanel(), null);
		}
		return jTabbedPane;
	}
	
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setFont(new java.awt.Font("Verdana", java.awt.Font.BOLD, 11));
			jPanel.setForeground(java.awt.Color.blue);
			jPanel.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1));
			jPanel.add(getJScrollPane(), null);
		}
		return jPanel;
	}
	
	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new java.awt.Rectangle(5,5,539,450));
			jScrollPane.setViewportView(getJTextArea());
		}
		return jScrollPane;
	}
	
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jComboBox.setEnabled(false);
			jComboBox.setSize(new java.awt.Dimension(200,22));
			jComboBox.setLocation(new java.awt.Point(330,45));
			jComboBox.setSelectedIndex(-1);
			jComboBox.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if(RelationManager.instance != null && jComboBox.getSelectedIndex() != -1){
						int pos = jComboBox.getSelectedIndex();
						RelationManager.instance.setCurrentRelation(pos);
						//System.out.println("-->: "+pos+" - "+RelationManager.instance.getCurrentRelation().getName());
						//DataMenu.setEnabled(true);
					}
				}
			});	
		}
		return jComboBox;
	}
	
	/**
	 * This method initializes jScrollPane1	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setBackground(java.awt.SystemColor.control);
			jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1));
			jScrollPane1.setBounds(new java.awt.Rectangle(3,12,211,587));
			jScrollPane1.setViewportView(getJTable());
		}
		return jScrollPane1;
	}
	
	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
			TableColumn tc1= new TableColumn();
			TableColumn tc2= new TableColumn();
			tc1.setPreferredWidth(30); 
			tc1.setHeaderValue("Generation");
			tc2.setHeaderValue("Information");
			tc2.setPreferredWidth(60);
			jTable.addColumn(tc1);
			jTable.addColumn(tc2);// JVE Generated
			tc1.setModelIndex(0);
			tc2.setModelIndex(1);
			jTable.setAutoCreateColumnsFromModel(false); // JVE Generated
			jTable.setModel(new ToDoListModel());
			jTable.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 10));
			jTable.addMouseListener(new java.awt.event.MouseListener() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					int row = jTable.getSelectedRow();
					if(row<logger.size()){
						Transaction transaction = (Transaction)logger.getTransaction(row);
						getJTextArea().setText(transaction.getOutput());
						jTransactionLabel.setText(transaction.toString());
					}
				}
				public void mousePressed(java.awt.event.MouseEvent e) {
				}
				public void mouseReleased(java.awt.event.MouseEvent e) {
				}
				public void mouseEntered(java.awt.event.MouseEvent e) {
				}
				public void mouseExited(java.awt.event.MouseEvent e) {
				}
			});
			
		}
		return jTable;
	}
	
	
	
	
	
	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setEditable(false);
			jTextArea.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 11));
			jTextArea.addCaretListener(new javax.swing.event.CaretListener() {
				public void caretUpdate(javax.swing.event.CaretEvent e) {
					jSaveFileButton.setEnabled(true);
				}
			});
		}
		return jTextArea;
	}
	
	/**
	 * @param args
	 */
//	@SuppressWarnings("deprecation")
//	public static void main(String[] args) {
//	(DataGenerator.createInstance()).show();
//	
//	RelationManager.createInstance();
//	//RelationManager.instanceRelationManager.addObserver(dg);
//	
//	/*for (double i = 3.5; i <= 7.5; i+=0.01) {
//	System.out.println(i);	
//	}
//	*/
//	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		logger = new LogTransaction();
		
		this.setTitle("Datasets Generator");
		//this.setLocation(new java.awt.Point(100,100));
		this.setVisible(true);
		this.setBackground(java.awt.SystemColor.control);
		this.setSize(800, 637);		
		this.setResizable(false);
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension freim = this.getSize();
		if (pantalla.width < freim.width){
			freim.width = pantalla.width;
		}
		if (pantalla.height < freim.height) {
			freim.height = pantalla.height;
		}
		this.setLocation((pantalla.width-freim.width)/2,(pantalla.height-freim.height)/2);
		
		
		this.setContentPane(getJContentPane());
		
		//Se agregan los convertidores 
		hash.put(Message.XML_CONVERTER,new XMLBayesConverter());
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jTransactionLabel = new JLabel();
			jTransactionLabel.setText("");
			jTransactionLabel.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
			jTransactionLabel.setBounds(new java.awt.Rectangle(225,563,477,35));
			jTransactionLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jLabel = new JLabel();
			jLabel.setEnabled(false);
			jLabel.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabel.setForeground(java.awt.Color.blue);
			jLabel.setBackground(java.awt.SystemColor.control);
			jLabel.setSize(new java.awt.Dimension(105,22));
			jLabel.setLocation(new java.awt.Point(225,45));
			jLabel.setText("Created Relations");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setEnabled(true);
			jContentPane.setVisible(true);
			jContentPane.setBackground(java.awt.SystemColor.control);
			jContentPane.add(getJTabbedPane(), null);
			jContentPane.add(getJComboBox(), null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJScrollPane1(), null);
			jContentPane.add(getJCreateRelationsButton(), null);
			jContentPane.add(getJGeneratorButton(), null);
			jContentPane.add(getJSaveFileButton(), null);
			jContentPane.add(getJHelpButton(), null);
//			jContentPane.add(getJParserButton(), null); Se comenta este boton porqe se decidio eliminar la funcinalidad del "File Convertor"
			jContentPane.add(jTransactionLabel, null);
		}
		return jContentPane;
	}
	
	public void updateRelation(Relation relation){
		RelationManager.instance.setRelations(relation);
		
		
		jComboBox.setEnabled(true);
		jLabel.setEnabled(true);
		jComboBox.addItem(relation.getName());
		
		jComboBox.setSelectedIndex(-1);
		
		
	}
	
	public void updateTransaction(Transaction transaction)
	{
		//traigo toda la info generada y aca creo una 
		//instancia de Transaction y lo agrego al logger y al logVisual
		
		logger.insertTransaction(transaction);
		String valueTransaction = transaction.getRelationName()+" - "+transaction.getRuleName();
		
		
		String dateTransaction = transaction.getDate();
		
		//Relation rela=(Relation)o;
		//jComboBox.setEnabled(true);
		//jLabel.setEnabled(true);
		//jComboBox.addItem(rela.getName());
		
		TableModel model = jTable.getModel();
		jTable.setForeground(Color.RED);
		model.setValueAt(valueTransaction,contTable,0);
		model.setValueAt(dateTransaction,contTable, 1);
		contTable++;
		jTextArea.setText(transaction.getOutput());
		
	}
	
	/**
	 * This method initializes jCresteRelationsButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJCreateRelationsButton() {
		if (jCreateRelationsButton == null) {
			jCreateRelationsButton = new JButton();
			jCreateRelationsButton.setText("Create Relation");
			jCreateRelationsButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jCreateRelationsButton.setLocation(new java.awt.Point(225,11));
			jCreateRelationsButton.setSize(new java.awt.Dimension(115,23));
			jCreateRelationsButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					(new RelationGenerator()).show();
				}
			});
		}
		return jCreateRelationsButton;
	}
	
	/**
	 * This method initializes jGeneratorButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJGeneratorButton() {
		if (jGeneratorButton == null) {
			jGeneratorButton = new JButton();
			jGeneratorButton.setEnabled(false);
			jGeneratorButton.setText("Instances Generator");
			jGeneratorButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jGeneratorButton.setSize(new java.awt.Dimension(115,23));
			jGeneratorButton.setLocation(new java.awt.Point(405,11));
			jGeneratorButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					setEnabled(false);
					getJGeneratorScrollPane().setVisible(true);
					getJGeneratorTree().setVisible(true);
					getJGeneratorWindow().show();
					
				}
			});
		}
		return jGeneratorButton;
	}
	
	/**
	 * This method initializes jSaveFileButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJSaveFileButton() {
		if (jSaveFileButton == null) {
			jSaveFileButton = new JButton();
			jSaveFileButton.setText("Save");
			jSaveFileButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jSaveFileButton.setEnabled(false);
			jSaveFileButton.setSize(new java.awt.Dimension(115,23));
			jSaveFileButton.setLocation(new java.awt.Point(585,11));
			jSaveFileButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JFileChooser fc = new JFileChooser();
					ImageFilter ifa=new ImageFilter(); 
					fc.addChoosableFileFilter(ifa);
					int returnVal = fc.showDialog(fc,"Save");
					
					if (returnVal == JFileChooser.APPROVE_OPTION) {
						
						try {
							File file = new File(fc.getSelectedFile()+".arff");
							BufferedWriter bw = new BufferedWriter(new FileWriter(file));
							jTextArea.write(bw);
							
							bw.close();
							
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}					
				}
			});
		}
		return jSaveFileButton;
	}
	public JWindow getJGeneratorWindow() {
		if(jGeneratorWindow == null)
			jGeneratorWindow  = new JWindow();
		jGeneratorWindow.setSize(new java.awt.Dimension(200,200));
		jGeneratorWindow.setContentPane(getJGeneratorScrollPane());
		jGeneratorWindow.setLocation(getJGeneratorButton().getLocationOnScreen());
		
		return jGeneratorWindow;
	}
	
	/**
	 * This method initializes jGeneratorScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJGeneratorScrollPane() {
		if (jGeneratorScrollPane == null) {
			jGeneratorScrollPane = new JScrollPane();
			jGeneratorScrollPane.setVisible(true);
			jGeneratorScrollPane.setViewportView(getJGeneratorTree());
			jGeneratorScrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1));
		}
		return jGeneratorScrollPane;
	}
	
	/**
	 * This method initializes jGeneratorTree	
	 * 	
	 * @return javax.swing.JTree	
	 */
	private JTree getJGeneratorTree() {
		if (jGeneratorTree == null) {
//			jGeneratorTree = new JTree();
			DefaultMutableTreeNode raiz = new DefaultMutableTreeNode("Data Generator");
			DefaultMutableTreeNode nodo1 = new DefaultMutableTreeNode("Random Generator");
			DefaultMutableTreeNode nodo2 = new DefaultMutableTreeNode("Association Random Generator");
			DefaultMutableTreeNode nodo3 = new DefaultMutableTreeNode("Random Generator with Weight");
			DefaultMutableTreeNode subraiz = new DefaultMutableTreeNode("Random Distributions");
			DefaultMutableTreeNode nodo4 = new DefaultMutableTreeNode("Poisson Distribution");
			DefaultMutableTreeNode nodo5 = new DefaultMutableTreeNode("Gaussian Distribution");
			DefaultMutableTreeNode nodo6 = new DefaultMutableTreeNode("Exponential Distribution");
			
			raiz.add(nodo1);
			raiz.add(nodo2);
			raiz.add(nodo3);
			subraiz.add(nodo4);
			subraiz.add(nodo5);
			subraiz.add(nodo6);
			raiz.add(subraiz);
			
			jGeneratorTree = new JTree(raiz);
			jGeneratorTree.setVisible(true);
			jGeneratorTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
				public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
					DefaultMutableTreeNode selection = (DefaultMutableTreeNode)jGeneratorTree.getLastSelectedPathComponent();
					//Se acomoda la interface
					selectGenerator(selection.toString());
					setEnabled(true);
					jGeneratorTree.setSelectionRow(0);
					getJGeneratorScrollPane().setVisible(false);
					jGeneratorTree.setVisible(false);						
					getJGeneratorWindow().dispose();
				}
			});
			
		}
		jGeneratorTree.setSelectionRow(0);
		return jGeneratorTree;
	}
	
	protected void selectGenerator(String selection) {
		if(selection.equals("Random Generator")){
			new RandomFrame().show();	
		}else if(selection.equals("Association Random Generator")){
			(new AssociationFrame()).show();
		}else if(selection.equals("Random Generator with Weight")){
			new RandomWithWeightFrame().show();
		}else if(selection.equals("Poisson Distribution")){
			(new RandomPoissonFrame()).show();
		}else if(selection.equals("Gaussian Distribution")){
			new RandomGaussianFrame().show();
		}
		else if(selection.equals("Exponential Distribution")){
			new RandomExponentialFrame().show();
		}
		
	}
	
	/**
	 * This method initializes jHelpButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJHelpButton() {
		if (jHelpButton == null) {
			jHelpButton = new JButton();
			jHelpButton.setText("Help");
			jHelpButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jHelpButton.setSize(new java.awt.Dimension(55,35));
			jHelpButton.setLocation(new java.awt.Point(718,563));
			jHelpButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					new HelpFrame(Message.TITLE_DATAGENERATOR,Message.BODY_DATAGENERATOR).show();
				}
			});
		}
		return jHelpButton;
	}

	/**
	 * This method initializes jParserButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJParserButton() {
		if (jParserButton == null) {
			jParserButton = new JButton();
			jParserButton.setText("File Converter");
			jParserButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jParserButton.setLocation(new java.awt.Point(538,38));
			jParserButton.setBackground(java.awt.SystemColor.control);
			jParserButton.setSize(new java.awt.Dimension(115,23));
			jParserButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jTree = null;
					getJChooseScrollPane1().setViewportView(getJTree());
					setEnabled(false);
					getJChooseScrollPane1().setVisible(true);
					getJTree().setVisible(true);
//					UserProfilingUI.eINSTANCE.setEnabled(false);
					getJWindow().show();
					
				}
			});

		}
		return jParserButton;
	}
	
	/**
	 * This method initializes jChooseScrollPane1	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJChooseScrollPane1() {
		if (jChooseScrollPane1 == null) {
			jChooseScrollPane1 = new JScrollPane();
			jChooseScrollPane1.setEnabled(true);
			jChooseScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1));
			jChooseScrollPane1.setViewportView(getJTree());
			jChooseScrollPane1.setVisible(false);
		}
		return jChooseScrollPane1;
	}

	/**
	 * This method initializes jTree1	
	 * 	
	 * @return javax.swing.JTree	
	 */
	private JTree getJTree() {
		if (jTree == null) {
			Enumeration enum1 = hash.keys();
			DefaultMutableTreeNode raiz = new DefaultMutableTreeNode(Message.CONVERTERS);

			while (enum1.hasMoreElements()) {
				String converter = (String) enum1.nextElement();
				DefaultMutableTreeNode nodo = new DefaultMutableTreeNode(converter);
				raiz.add(nodo);
				
			}
			
			jTree = new JTree(raiz);
			jTree
			.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
				public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
					DefaultMutableTreeNode selection = (DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
					if(isConverter(selection.toString())){
//						getJFilterTextField().setText(selection.toString());
						//Se acomoda la interface
						setEnabled(true);
						getJChooseScrollPane1().setVisible(false);
						getJTree().setVisible(false);						
						getJWindow().dispose();
//						la siguiente linea es para que quede selccionada la raiz
						getJTree().setSelectionRow(0);
						UserProfilingUI.eINSTANCE.setEnabled(true);
						Converter conv = hash.get(selection.toString());
						
//						String output = null;
						try {
							String output = conv.convert();
							getJTextArea().setText(output.toString());
							Transaction trans = new Transaction(output,conv.getRelationName(),conv.getClass().getSimpleName());
							updateTransaction(trans);
						} catch (Exception e1) {
							JOptionPane.showMessageDialog(null,
									Message.ERROR_LOADED_CONVERTER,
									Message.ERROR_LOADED_CONVERTER_TITLE,
									JOptionPane.ERROR_MESSAGE);
						}
//						if(output != null){
//							getJTextArea().setText(output.toString());
//							Transaction trans = new Transaction(output,conv.getRelationName(),conv.getClass().getSimpleName());
//							updateTransaction(trans);
//							//TODO agegar en la ayuda
//						}else{
//							JOptionPane.showMessageDialog(null,
//									Message.ERROR_LOADED_CONVERTER,
//									Message.ERROR_LOADED_CONVERTER_TITLE,
//									JOptionPane.ERROR_MESSAGE);
//						}
					}
				}
			});
		}
		jTree.setSelectionRow(0);
		return jTree;
	}
	
	/**
	 * Retorna si el converter es uno de los algoritmos agregados
	 * 
	 * */
	protected boolean isConverter(String converter) {
		if(converter.equals(Message.CONVERTERS)){
			return false;
		}
		if(hash.containsKey(converter)){
			return true;
		}
		return false;
	}

	public JWindow getJWindow() {
		if(jWindow == null)
			jWindow = new JWindow();
		jWindow.setSize(new java.awt.Dimension(150,200));
		jWindow.setLocation(getJParserButton().getLocationOnScreen());
		jWindow.setContentPane(getJChooseScrollPane1());
		
		
		return jWindow;
	}

	
}  //  @jve:decl-index=0:visual-constraint="9,12"
